<%-- 
    Document   : home
    Created on : 2-sep-2011, 11:18:54
    Author     : fgo
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="includes/header.jsp" %>

<script type="text/javascript">                                         

    function Toggle(id){
        $('#' + id).toggle();
    }
   
</script>

<u><a onclick="Toggle('itemTable'); return false;" href="">Items</a></u>
<table id="itemTable" style="display: none; ">
    <tr><td>Name</td></tr>
    <c:forEach items="${items}" var="item">
        <tr>
            <td>
                <form action="admin/item/update" method="POST">
                    <input type="hidden" id="id" name="id" value="${item.id}" />
                    <input type="text" id="name" name="name" value="${item.name}" />
            </td>
            <td>
                <input type="submit" value="update" />
                </form>
            </td>
            <td>
                <form action="admin/item/delete" method="POST">
                    <input type="hidden" id="id" name="id" value="${item.id}" />
                    <input type="submit" value="delete" />
                </form>
            </td>
        </tr>

    </c:forEach>
    <form action="admin/item/new" method="POST">
        <tr>
            <td>
                <input type="text" id="name" name="name" />
            </td>
            <td>
                <input type="submit" value="create" />
            </td>
        </tr>
    </form>
</table>
<br />
<u><a onclick="Toggle('userTable'); return false;" href="">Users</a></u>
<table id="userTable" style="display: none; ">
    <tr><td>Name</td><td>Password</td><td>Admin</td>
        <c:forEach items="${groups}" var="group">
            <td>${group.name}</td>
        </c:forEach>
    </tr>
    <c:forEach items="${users}" var="user">
        <tr>
            <td>
                <form action="admin/user/update" method="POST">
                    <input type="hidden" id="id" name="id" value="${user.id}" />
                    <input type="text" id="name" name="name" value="${user.name}" />
            </td>
            <td>
                <input type="password" id="password" name="new_password" />
            </td>
            <td>
                <input type="checkbox" id="admin" name="admin" <c:if test="${user.admin}">CHECKED</c:if> />
            </td>
            <c:forEach items="${groups}" var="group">
                <td>
                    <input type="checkbox" id="${group.id}" name="${group.id}" <c:if test="${memberships[user][group]}">CHECKED</c:if> />
                </td>
            </c:forEach>
            <td>
                <input type="submit" value="update" />
                </form>
            </td>
            <td>
                <form action="admin/user/delete" method="POST">
                    <input type="hidden" id="id" name="id" value="${user.id}" />
                    <input type="submit" value="delete" />
                </form>
            </td>
        </tr>
    </c:forEach>
    <form action="admin/user/create" method="POST">
        <tr>
            <td>
                <input type="text" id="name" name="name" />
            </td>
            <td>
                <input type="password" id="password" name="new_password" />
            </td>
            <td>
                <input type="checkbox" id="admin" name="admin" />
            </td>
            <c:forEach items="${groups}" var="group">
                <td>
                    <input type="checkbox" id="${group.id}" name="${group.id}" />
                </td>
            </c:forEach>
            <td>
                <input type="submit" value="create" />
            </td>
        </tr>
    </form>
</table>
<br />
<u><a onclick="Toggle('userGroupTable'); return false;" href="">UserGroups</a></u>
<table id="userGroupTable" style="display: none; ">
    <tr><td>Name</td></tr>
    <c:forEach items="${groups}" var="group">
        <tr>
            <td>
                <form action="admin/group/update" method="POST">
                    <input type="hidden" id="id" name="id" value="${group.id}" />
                    <input type="text" id="name" name="name" value="${group.name}" />
            </td>
            <td>
                <input type="submit" value="update" />
                </form>
            </td>
            <td>
                <form action="admin/group/delete" method="POST">
                    <input type="hidden" id="id" name="id" value="${group.id}" />
                    <input type="submit" value="delete" />
                </form>
            </td>
        </tr>
    </c:forEach>
    <form action="admin/group/create" method="POST">
        <tr>
            <td>
                <input type="text" id="name" name="name" />
            </td>
            <td>
                <input type="submit" value="create" />
            </td>
        </tr>
    </form>
</table>

<%@include file="includes/footer.jsp" %>
